#ifndef __BUOLA_GUI_CIMAGEMATRIX_H__
#define __BUOLA_GUI_CIMAGEMATRIX_H__

#include <buola/gui.h>
#include <buola/image/cpicture.h>

namespace buola { namespace gui {

///\addtogroup gui
///@{

////////////////////////////////////////////////////////////////////////////

/// matricial image

/// Contains an image which can be rendered at different sizes, keeping the
/// edges the same and scaling or repeating what is on the center
///
///////////////////////////////////////////////////////////////////////////

class CImageMatrix
{
public:
    //! flags for drawing
    enum EFlags
    {
        FLAG_NONE=0,
        SCALE=(1<<0),
        NOLEFT=(1<<1),
        NORIGHT=(1<<2),
        NOTOP=(1<<3),
        NOBOTTOM=(1<<4),
        REPEATONE=(1<<5)
    };

    DECLARE_FRIEND_ENUM_BITOPS(EFlags)

//! \name constructor and destructor
//@{
    CImageMatrix();
    virtual ~CImageMatrix();
//@}

public:
//! \name public interface
//@{
    //! \brief creates the image
    //!
    //! \param pI source image
    //! \param pB rectangle, where each component represents the size of the
    //! border on that side
    void CreateWithBorder(img::CImage_rgba8 &&pI,const CRect_d &pB);

    //! \brief creates the image
    //!
    //! \param pI source image
    //! \param pR rectangle of the center tile
    void Create(img::CImage_rgba8 &&pI,const CRect_d &pR);

    //! from 3 images (horizontally)
    void Create3H(const img::CView_rgba8 &pW,const img::CView_rgba8 &pC,const img::CView_rgba8 &pE);
    //! from 3 images (vertically)
    void Create3V(const img::CView_rgba8 &pN,const img::CView_rgba8 &pC,const img::CView_rgba8 &pS);

    //! creates a rounded rectangle
    void CreateRoundRect(const img::CColor&,int pR);
    //! creates a rounded empty rectangle
    void CreateRoundFrame(const img::CColor&,int pRI,int pRO,const img::CColor&);

    //! draws the image
    void Draw(img::CGC*,const CRect_d&,EFlags=FLAG_NONE);

////////////////////////////////////////////
////////////////////////////////////////////
//////////////// internal //////////////////
////////////////////////////////////////////
////////////////////////////////////////////
protected:
    img::CPicture mImage;
    CRect_d mRect; //!< rectangle of center tile
    CSize_d mSize;
    EFlags mFlags;
};

///@}

/*namespace gui*/ } /*namespace buola*/ }

#endif
